//
//  LeftDrawerViewController.m
//  UEHtml-iOS
//
//  Created by Qun He on 13-9-25.
//  Copyright (c) 2013年 Qun He. All rights reserved.
//

#import "LeftDrawerViewController.h"
#import "UIConstanstDefine.h"
#import "UENavigatorCell.h"

#define MAX_OPTION_COUNT 5

@interface LeftDrawerViewController ()

@end

@implementation LeftDrawerViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    tableTitles = [NSArray arrayWithObjects:@"首页",@"原创",@"酷站",@"灵感",@"设置",nil];
    self.functionList = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), self.view.bounds.size.height)];
    self.functionList.delegate = self;
    self.functionList.dataSource = self;
    self.functionList.backgroundColor = HEXCOLOR(0x404345);
    self.functionList.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.functionList setScrollsToTop:YES];
    [self.view addSubview:self.functionList];
    self.view.backgroundColor = [UIColor clearColor];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//-----
- (void)viewDidUnload
{
    tableTitles = nil;
    [self setFunctionList:nil];
    [super viewDidUnload];
}


#pragma mark - Public

- (void)setVisible:(BOOL)visible {
    self.view.hidden = !visible;
}

#pragma mark - UITableView delegate

// Called after the user changes the selection.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // ...
//    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    UENavigatorCell* cell = (UENavigatorCell*)[tableView cellForRowAtIndexPath:indexPath];
    cell.selectedBackgroundView.backgroundColor = HEXCOLOR(0x1f1f1f);
    
    [SHARE_APPDELEGATE menuItemSelected:indexPath.row title:[tableTitles objectAtIndex:indexPath.row]];
    
}

#pragma mark - UITableView datasource

//- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
//    return @"Ethan Gao";
//}
//
//- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
//    return @"Heq.shinoda";
//}
-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 86;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [tableTitles count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"LeftViewTableCell";
	UENavigatorCell *cell = (UENavigatorCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UENavigatorCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        if(indexPath.row == 0)
        {
            [tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
            cell.selectedBackgroundView.backgroundColor = HEXCOLOR(0x1f1f1f);
        }
	}
    
    cell.index = indexPath.row;
    
    cell.optionName.text = [tableTitles objectAtIndex:indexPath.row];
	return cell;
}

@end
